<?php

/**
 *  @FileComment            [后台节点模型]
 *  @ProjectName             项目名称：JDshop
 *  @FileName                   文件名称：NodeModel.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-26 12:10:49
 *  *
 */
class NodeModel extends Model {

        public $table = 'node';
        public $validate = array(
            array('name', 'nonull', '节点不能为空', 2, 3),
        );

        public function get_tree_data() {
                $data = $this->all();
                return Data::tree($data, 'name', 'nid', 'pid');
        }

        public function get_one_data($nid) {
                return $this->where(array('nid' => $nid))->find();
        }

        public function del_data($nid) {
                $data = $this->where(array('pid' => $nid))->find();
                if (!empty($data)) {
                        return false;
                }
                return $this->where(array('nid' => $nid))->del();
        }

        public function add_son() {
                $data = array(
                    'name' => Q('post.name'),
                    'state' => 1,
                    'sort' => 100,
                    'pid' => Q('post.pid', 0, 'intval'),
                    'level' => Q('post.level', 0, 'intval')
                );
                return $this->add($data);
        }

}
